package org.snackframework.core;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * @author allen Jun 25, 2010
 *
 */
public class ScreenCacheElement
{
	private static Log log = LogFactory.getLog(ScreenCacheElement.class);
	private Class clazz;
	private Object object;
	private boolean singleton=true;
	private String screen;
	
	private boolean initProperty=false;
	
	public ScreenCacheElement()
	{}
	
	public ScreenCacheElement(Class clazz)
	{
		this.clazz=clazz;
	}
	
	public ScreenCacheElement(Class clazz,String url)
	{
		this.clazz=clazz;
		this.screen=url;
	}
	
	public ScreenCacheElement(Class clazz,boolean singleton)
	{
		this.clazz=clazz;
		this.singleton=singleton;
	}
	
	public ScreenCacheElement(Class clazz,boolean singleton,String url)
	{
		this.clazz=clazz;
		this.singleton=singleton;
		this.screen=url;
	}

	public Class getClazz()
	{
		return clazz;
	}

	public void setClazz(Class clazz)
	{
		this.clazz = clazz;
	}

	public Object getObject()
	{
		return object;
	}

	public boolean isInstantiated()
	{
		return object==null ? false : true;
	}
	
	public boolean isSingleton()
	{
		return singleton;
	}
	
	/**
	 * non-multythread safe
	 */
	public void createSingletonInstance()
	{
		try
		{
			this.object=this.clazz.newInstance();
		}
		catch (InstantiationException e)
		{
			e.printStackTrace();
		}
		catch (IllegalAccessException e)
		{
			e.printStackTrace();
		}
	}

	public String getScreen()
	{
		return screen;
	}

	public void setScreen(String screen)
	{
		this.screen = screen;
	}
	
	public void finishInitProperty()
	{
		this.initProperty=true;
	}
	
	public boolean isInitProperty()
	{
		return initProperty;
	}
}
